package com.hiyee.platform.response;

/**
 * 统一的 api 接口返回格式定义
 *
 * @author WangBin
 */
public class ResponseJsonResult {

    // 业务响应状态码 200 500 等等
    private Integer status;
    // 业务响应消息
    private String msg;
    // 响应数据
    private Object data;

    /**
     * 构造函数 返回成功并携带数据
     *
     * @param data
     */
    public ResponseJsonResult(Object data) {
        this.status = ResponseStatusEnum.SUCCESS.getStatus();
        this.msg = ResponseStatusEnum.SUCCESS.getMsg();
        this.data = data;
    }

    /**
     * 构造函数 返回指定枚举
     *
     * @param statusEnum
     */
    public ResponseJsonResult(ResponseStatusEnum statusEnum) {
        this.status = statusEnum.getStatus();
        this.msg = statusEnum.getMsg();
    }

    /**
     * 构造函数 返回指定枚举
     *
     * @param statusEnum
     */
    public ResponseJsonResult(ResponseStatusEnum statusEnum, String errorMsg) {
        this.status = statusEnum.getStatus();
        this.msg = errorMsg;
    }

    /**
     * 返回成功
     *
     * @return
     */
    public static ResponseJsonResult success() {
        return new ResponseJsonResult(ResponseStatusEnum.SUCCESS);
    }

    /**
     * 返回错误枚举
     *
     * @param statusEnum
     * @return
     */
    public static ResponseJsonResult error(ResponseStatusEnum statusEnum) {
        return new ResponseJsonResult(statusEnum);
    }

    /**
     * 返回错误自定义错误
     *
     * @param String errorMsg
     * @return
     */
    public static ResponseJsonResult error(String errorMsg) {
        return new ResponseJsonResult(ResponseStatusEnum.FAIL, errorMsg);
    }

    /**
     * 返回成功携带数据
     *
     * @param object
     * @return
     */
    public static ResponseJsonResult success(Object object) {
        return new ResponseJsonResult(object);
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
